﻿using tricogol.metro.Data;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Threading.Tasks;
using Windows.System;
using Windows.Foundation;


// The Grouped Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234231

namespace tricogol.metro
{
    /// <summary>
    /// A page that displays a grouped collection of items.
    /// </summary>
    public sealed partial class GroupedItemsPage : tricogol.metro.Common.LayoutAwarePage
    {

        GroupedItemsPageViewModel obVM = new GroupedItemsPageViewModel();
        Configuracion _config =  Configuracion.Instancia;
        Models.Equipo EquipoSeleccionado = new Models.Equipo();




        public GroupedItemsPage()
        {
            this.InitializeComponent();
            CargarArchivoConfiguracion();
           
        }

        public async void CargarArchivoConfiguracion()
           {
               if (!GroupedItemsPageViewModel.estado)
               {

                   string elegido = "";
                   await _config.Inicializar();

                   if (_config.contenido == "")
                       obVM.OpenDialog_Executed();

                       // EJecutar el menu contextual de Equipos
                   else
                       elegido = _config.contenido;
                   //llamar a azure
               }
              

           }


        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data
            var sampleDataGroups = SampleDataSource.GetGroups((String)navigationParameter);
            this.DefaultViewModel["Groups"] = sampleDataGroups;
        }

        /// <summary>
        /// Invoked when a group header is clicked.
        /// </summary>
        /// <param name="sender">The Button used as a group header for the selected group.</param>
        /// <param name="e">Event data that describes how the click was initiated.</param>
        void Header_Click(object sender, RoutedEventArgs e)
        {
            // Determine what group the Button instance represents
            //var group = (sender as FrameworkElement).DataContext;

            // Navigate to the appropriate destination page, configuring the new page
            // by passing required information as a navigation parameter
            //this.Frame.Navigate(typeof(GroupDetailPage), ((SampleDataGroup)group).UniqueId);
        }

        /// <summary>
        /// Invoked when an item within a group is clicked.
        /// </summary>
        /// <param name="sender">The GridView (or ListView when the application is snapped)
        /// displaying the item clicked.</param>
        /// <param name="e">Event data that describes the item clicked.</param>
        void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Navigate to the appropriate destination page, configuring the new page
            // by passing required information as a navigation parameter
            //var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;
            //this.Frame.Navigate(typeof(ItemDetailPage), itemId);
        }

        private void pageRoot_Loaded(object sender, RoutedEventArgs e)
        {




        }

       
        private async void GridView_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.deportivocuenca.com.ec/");
            await Windows.System.Launcher.LaunchUriAsync(url);
            
        }

        private async void GridView_Tapped_2(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.barcelonasc.com.ec/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_3(object sender, TappedRoutedEventArgs e)
        {

            Uri url = new Uri(@"http://www.emelec.com.ec/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_4(object sender, TappedRoutedEventArgs e)
        {

            Uri url = new Uri(@"http://www.independientedelvalle.com.ec/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_5(object sender, TappedRoutedEventArgs e)
        {

            Uri url = new Uri(@"http://www.ldu.com.ec/portal/index");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_6(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.ligadeloja.com/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_7(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.google.com.ec/webhp?sourceid=chrome-instant&ie=UTF-8&ion=1#hl=en&q=club+social+y+deportivo+macara&stick=H4sIAAAAAAAAAGOovnz8BQMDAy8HixKnfq6-gblpimnevfksutP3HG3YW8mjq-zVtEM_oO4IAA4ZIUIqAAAA&sa=X&ei=bKtsUILkAoPu9ATZ-4DwDg&ved=0CIwBEOkTMBE&bav=on.2,or.r_gc.r_pw.r_qf.&fp=7c07ccaba825f18a&ion=1&biw=1280&bih=685");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }
          
        private async void GridView_Tapped_8(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.mantafutbolclub.com/");
            await Windows.System.Launcher.LaunchUriAsync(url);

        }
        
        private async void GridView_Tapped_9(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.elnacional.ec/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_10(object sender, TappedRoutedEventArgs e)
        {
            Uri url = new Uri(@"http://www.olmedoderiobamba.com/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_11(object sender, TappedRoutedEventArgs e)
        {

            Uri url = new Uri(@"http://www.deportivoquito.com/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void GridView_Tapped_12(object sender, TappedRoutedEventArgs e)
        {

            Uri url = new Uri(@"http://www.tecnicouniversitario.ec/");
            await Windows.System.Launcher.LaunchUriAsync(url);
        }

        private async void CambioEquipo_Tapped(object sender, TappedRoutedEventArgs e)
        {
            
            await _config.BorrarArchivo();
            await _config.LeerContenido();
            obVM.OpenDialog_Executed();
            
        }

        private void CambioEquipo_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        
    }

}
